# -*- coding: utf-8 -*-
"""
@Version : 
@Author  : ChenMZ
@Time    : 2025/09/23
@File    : __init__.py.py
@Desc    : 
@Modify  : 
"""
import enum
from typing import Callable
from . import _container
_signal_cpu_ = _container.CpuSignalContainer()


class _SignalBus(enum.Enum):
    def emit(self, *args):
        # 通过getattr获取单例中的信号，并发射
        if not hasattr(_signal_cpu_, self.value):
            return None
        signal = getattr(_signal_cpu_, self.value)
        signal.emit(*args)

    def connect(self, func: Callable):
        signal = getattr(_signal_cpu_, self.value)
        signal.connect(func)

    @classmethod
    def member(cls):
        return cls.__members__

    def connect_all(self, func: Callable):
        for name, signal in self.__class__.member():
            signal.connect(func)


class CpuMonitorSignalBus(_SignalBus):
    signal_get_attr_req = "signal_get_attr_req"
    signal_get_attr_resp = "signal_get_attr_resp"
    signal_dynamic_cap = "signal_dynamic_cap"
    signal_dynamic_cap_val = "signal_dynamic_cap_val"
    signal_view_cap_clear = "signal_view_cap_clear"



